﻿using System.Collections.Generic;
using System.Linq;
using DevFramework.Core.Aspects.CacheAspects;
using DevFramework.Entities.ComplexType;


namespace DevFramework.Business.Concrete.Managers
{
    
    public class CartManager
    {
        private readonly List<Cart> _carts;

        public CartManager()
        {
            _carts = new List<Cart>();
        }

        public void Ekle(Cart cart)
        {
            var urun = _carts.FirstOrDefault(t => t.Product.ProductId == cart.Product.ProductId);
            if (urun == null)
                _carts.Add(cart);
            else
                urun.Quantity += cart.Quantity;
        }

        public void Remove(int productId)
        {
            var urun = _carts.FirstOrDefault(t => t.Product.ProductId == productId);
            _carts.Remove(urun);
        }
       
        public List<Cart> List()
        {
            return _carts;
        }
        
        public Cart Get(int productId)
        {
            return _carts.FirstOrDefault(t => t.Product.ProductId == productId);
        }
     
        public decimal ToplamFiyat
        {
            get { return _carts.Sum(t => t.Quantity * t.Product.UnitPrice); }
        }
      
        public decimal TotalAmount
        {
            get { return _carts.Sum(t => t.Quantity); }
        }
    }
}
